package com.yishan.gulimall.springsecurity.controller;

import com.yishan.gulimall.springsecurity.config.R;
import com.yishan.gulimall.springsecurity.domain.User;
import com.yishan.gulimall.springsecurity.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
public class LoginController {
    @Autowired
    private LoginService loginService;
    @PostMapping("/user/login")
    public R  login(@RequestBody User user) {
        return loginService.login(user);
    }

    @PostMapping("/user/logout")
    public R logout(HttpServletRequest request) {
        return loginService.logout(request);
    }

    @PostMapping("/user/texe")
    @PreAuthorize("hasAuthority('UserManagement')")
    public R texe() {
        return R.success("texe");
    }

    @PostMapping("/user/text")
    @PreAuthorize("hasAuthority('text')")
    public R text() {
        return R.success("text");
    }
}
